const React = require('react');
const {
  View,
  WebView,
  Picker,
  StyleSheet
} = require('react-native');
const {
  JDText,
  JDDevice,
  JDButton,
  JDPicker
} = require('@areslabs/jdreact-core-lib');
const PageContainer = require('../../components/PageContainer');

const PICKER_CONFIGS = [
  {
    label: 'Java',
    value: 'Java',
  },
  {
    label: 'JavaScript',
    value: 'JavaScript',
  },
  {
    label: 'Python',
    value: 'Python',
  },
  {
    label: 'PHP',
    value: 'PHP',
  },
  {
    label: 'GoLang',
    value: 'GoLang',
  },
  {
    label: 'C++',
    value: 'C++',
  },
  {
    label: 'CSS',
    value: 'CSS',
  },
  {
    label: 'HTML5',
    value: 'HTML5',
  },
  {
    label: 'TypeScript',
    value: 'TypeScript',
  },
  {
    label: 'Angular',
    value: 'Angular',
  },
  {
    label: 'NativeScript',
    value: 'NativeScript',
  },
  {
    label: 'ReactJS',
    value: 'ReactJS',
  },
  {
    label: 'Backbone',
    value: 'Backbone',
  },
  {
    label: 'ReactNative',
    value: 'ReactNative',
  },
  {
    label: 'Vue',
    value: 'Vue',
  },
];

class JDPickierExample extends React.Component {
  state = {
    language: 'Java',
    show: false,
  };

  render() {
    return (
      <PageContainer title={this.props.title} bodyStyle={styles.bodyPanel}>
        <JDButton onPress={this.onShow}>
          <JDText style={{color: '#FFF'}}>当前值: {this.state.language}</JDText>
        </JDButton>
        <JDPicker
          show={this.state.show}
          onClose={this.onClose}
          selectedValue={this.state.language}
          onValueChange={(lang) => this.setState({language: lang, show: false})}>
          { PICKER_CONFIGS.map((item, index) => 
          (
            <View style={{height:40, justifyContent: 'center'}} value={item.value} key={index} >
              <JDText>{item.label}</JDText>

            </View>
            // <JDPicker.Item label={item.label} value={item.value} key={item.value} />
          )) }
        </JDPicker>
      </PageContainer>
    );
  }

  onClose = () => {
    this.setState({show: false,})
  };

  onShow = () => {
    this.setState({show: true});
  };
}

const styles = StyleSheet.create({
  bodyPanel: {
    padding: JDDevice.getRpx(20),
  },
});

module.exports = JDPickierExample;
